package com.zhledu.string;

import com.zhledu.course.string.GenerateChineseName;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

public class GenerateStudent {
    private long num = 100 * 100 * 100 ;
    private String[] major = {"电子商务技术", "移动应用技术开发", "大数据技术与应用", "数字媒体艺术", "广告艺术设计", "会计", "计算机技术与应用", "房地产评估", "物业管理"};

    @Test
    public void testStudent2File() throws Exception {
        StringBuffer sb = null;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        int n = 0;
        BufferedWriter writer = null;
        for (int i = 0; i <= num; i++) {
            sb = new StringBuffer();
            if (i % 1000 == 0) {
                try {
                    if (writer != null) {
                        writer.close();
                    }
                } catch (Exception e) {

                }
                writer = new BufferedWriter(new FileWriter(new File("/Users/zhli/Desktop/student/students-" + n + ".txt")));
                n++;
                System.out.println(n * 1000 + "条记录");
            }
            sb.append((2020000000 + n * 1000 + i % 1000) + " ");
            sb.append(GenerateChineseName.getChineseName(i % 2 == 0) + " ");
            String idNo = GenerateChineseName.getIdNo(i % 2 == 0);
            sb.append(idNo.substring(6, 10) + "-" + idNo.substring(10, 12) + "-" + idNo.substring(12, 14) + " ");
            sb.append(idNo);
            sb.append(" " + GenerateChineseName.getNation(null));
            sb.append(" " + GenerateChineseName.getPhone());
            sb.append(" " + major[GenerateChineseName.getNum(0, major.length - 1)]);
            sb.append(" " + GenerateChineseName.getEmail());
            sb.append(" " + GenerateChineseName.getUserNameOrPassword());
            sb.append(" " + GenerateChineseName.getUserNameOrPassword());
            sb.append(" " + sdf.format(new Date()));
            sb.append(" " + sdf.format(new Date()));
            sb.append(" " + 0);
            writer.write(sb.toString());
            writer.newLine();
        }
        if(writer!=null)
        {
            writer.close();
        }
        System.out.println("记录生成");
    }

}
